/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jeff.springWebTestNG.aspect;

import java.util.LinkedList;
import java.util.List;
import org.springframework.stereotype.Component;

/**
 *
 * @author winnie
 */
@Component("aspectOrderStore")
public class AspectOrderStore {
    private List<Integer> ascOrders = new LinkedList<Integer>();
    private List<Integer> descOrders = new LinkedList<Integer>();
    
    public synchronized int registerOrder(int desiredOrder, boolean asc) {
        List<Integer> orders = (asc)? ascOrders : descOrders;
        
        int actualOrder = -1;
        if (orders.contains(desiredOrder)) {
            getNextOrder(asc);
        } else {
            actualOrder = desiredOrder;
        }
        
        orders.add(actualOrder);
        
        return actualOrder;
    }

    private int getNextOrder(boolean asc) {
        if (asc) {
            return getNextLargerOrder(ascOrders);
        } else {
            return getNextSmallerOrder(descOrders);
        }
    }

    private int getNextLargerOrder(List<Integer> orders) {
        int order = 0;
        
        
        
        return order;
    }

    private int getNextSmallerOrder(List<Integer> orders) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    
    
}
